<?xml version='1.0' encoding='UTF-8' ?>

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:fn="http://java.sun.com/jsp/jstl/functions"
                xmlns:h="http://java.sun.com/jsf/html"
                template="/WEB-INF/templates/default.xhtml">

    <ui:define name="content">
        <h:form id="deliverySearch">
            <h:outputText value="#{msg['search']}: " />
            <h:inputText rendered="#{!fn:contains(deliveryManager.searchAttributeType, 'Date') 
                                     and deliveryManager.searchAttributeType != 'customer' 
                                     and deliveryManager.searchAttributeType != 'deliveryBoy'}" 
                         value="#{deliveryManager.searchField}" />
            <h:inputText rendered="#{fn:contains(deliveryManager.searchAttributeType, 'Date')}" value="#{deliveryManager.dateFrom}" />
            <h:inputText rendered="#{fn:contains(deliveryManager.searchAttributeType, 'Date')}" value="#{deliveryManager.dateTo}" />
            <h:selectOneMenu rendered="#{deliveryManager.searchAttributeType == 'customer'}" id="som1" value="#{deliveryManager.searchCustomerId}">
                <c:forEach items="#{customers}" var="customer">
                    <f:selectItem itemLabel="#{customer.name}" itemValue="#{customer.id}" />
                </c:forEach>
            </h:selectOneMenu>
            <h:selectOneMenu rendered="#{deliveryManager.searchAttributeType == 'deliveryBoy'}" id="som2" value="#{deliveryManager.searchDeliveryBoyId}">
                <c:forEach items="#{deliveryBoys}" var="deliveryBoy">
                    <f:selectItem itemLabel="#{deliveryBoy.name}" itemValue="#{deliveryBoy.id}" />
                </c:forEach>
            </h:selectOneMenu>

            <h:selectOneMenu id="som3" value="#{deliveryManager.searchAttributeType}">
                <f:selectItem id="si31" itemLabel="#{msg['delivery.customer']}" itemValue="customer" />
                <f:selectItem id="si32" itemLabel="#{msg['delivery.creationDate']}" itemValue="creationDate" />
                <f:selectItem id="si33" itemLabel="#{msg['delivery.recipientName']}" itemValue="recipient" />
                <f:selectItem id="si34" itemLabel="#{msg['delivery.recipientAddress']}" itemValue="address" />
                <f:selectItem id="si35" itemLabel="#{msg['delivery.recipientCity']}" itemValue="city" />
                <f:selectItem id="si36" itemLabel="#{msg['delivery.recipientZip']}" itemValue="zip" />
                <f:selectItem id="si37" itemLabel="#{msg['delivery.deliveryBoy']}" itemValue="deliveryBoy" />
                <f:selectItem id="si38" itemLabel="#{msg['delivery.deliveryDate']}" itemValue="deliveryDate" />
                <f:ajax render="deliverySearch"/>
            </h:selectOneMenu>
            <h:commandButton class="btn" value="#{msg['search']}" />
            <h:commandButton class="btn" value="#{msg['show.all.deliveries']}" action="#{deliveryManager.setSearchAttributeType('')}" />
        </h:form>

        <ui:include src="deliveryForm.xhtml" /><br/>

        <h:dataTable class="table table-striped table-bordered" value="#{deliveries}" var="delivery" rendered="#{not empty deliveries}">
            <h:column>
                <f:facet name="header">#{msg['delivery.deliveryNumber']}</f:facet>
                <h:outputText value="#{delivery.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['delivery.customer']}</f:facet>
                <h:outputText value="#{delivery.customer.name}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['delivery.creationDate']}</f:facet>
                <h:outputText value="#{delivery.creationDate}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['delivery.recipientName']}</f:facet>
                <h:outputText value="#{delivery.recipientName}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['delivery.recipientAddress']}</f:facet>
                <h:outputText value="#{delivery.recipientAddress}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['delivery.recipientCity']}</f:facet>
                <h:outputText value="#{delivery.recipientCity}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['delivery.recipientZip']}</f:facet>
                <h:outputText value="#{delivery.recipientZip}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['delivery.deliveryBoy']}</f:facet>
                <h:outputText value="#{delivery.deliveryBoy.name}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['delivery.deliveryDate']}</f:facet>
                <h:outputText value="#{delivery.deliveryDate}"/>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['default.packages']}</f:facet>
                <h:button class="btn" outcome="packages" value="#{msg['default.packages']}">
                    <f:param name="id" value="#{delivery.id}" />
                </h:button>
            </h:column>
            <h:column>
                <f:facet name="header">#{msg['actions']}</f:facet>
                <h:button class="btn" outcome="/pages/admin/deliveryDelete" value="#{msg['form.delete']}" >
                    <f:param name="id" value="#{delivery.id}" />
                </h:button>
            </h:column>
        </h:dataTable>
    </ui:define>
</ui:composition>

